//
//  TRMemuCell.m
//  WeiMiLan
//
//  Created by Mac on 14-7-17.
//  Copyright (c) 2014年 Mac. All rights reserved.
//

#import "TRMemuCell.h"

@interface TRMemuCell ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *nameLabelTextWidth;
@property (nonatomic, weak) UIView *lineView;
@property (weak, nonatomic) IBOutlet UIView *bottomView;

@end

@implementation TRMemuCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        // Initialization code
    }
    return self;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = [UIColor colorWithWhite:0.956 alpha:1.000];
    [self addSubview:lineView];
    self.lineView = lineView;
    
}
- (void)setInfo:(NSDictionary *)info
{
    _info = info;
  
    if ([info ql_hasObjectForKey:@"advertisementPic"]) {
        NSString *url = info[@"advertisementPic"];
        if (url) {
            self.adImageView.hidden = NO;
            [self.adImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:ApplicationDelegate.loadingImage];
        } 
        self.imageViewIcon.hidden = YES;
        self.viewLabels.hidden = YES;
        self.dscriView.hidden = YES;
  
    }else{
        self.adImageView.hidden = YES;
        self.imageViewIcon.hidden = NO;
        self.dscriView.hidden = NO;
        self.backgroundColor=[UIColor clearColor];
        self.imageViewIcon.image = [UIImage imageNamed:@"1"];
        NSString *url = info[@"THUMBNAIL_URL"];
        if (url) {
            [self.imageViewIcon sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:ApplicationDelegate.loadingImage];
        }
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyyMMddHHmmss"];
        NSDate *createDate = [formatter dateFromString:[self.info ql_stringForKey:@"CREATE_DATE"]];
        
        
        NSString *str = [NSString stringWithFormat:@"%@",[createDate ql_ToString]];
        str = [str substringFromIndex:5];
        self.timeLabel.text =str;
       
        
        
        self.label1.text = [info ql_stringForKey:@"USER_NAME"];
       // self.label2.textAlignment = UIControlContentVerticalAlignmentTop;
        self.label2.text = [NSString stringWithFormat:@"%@",[info ql_stringForKey:@"DESCRIPTION"]];
        int comment = [info ql_intForKey:@"COMMENT_NUM"];
        self.label3.text = [NSString stringWithFormat:@"评论 %d",comment];
        
        self.viewLabels.hidden = NO;
      //  _nameLabel.hidden = YES;
     
    }
    UIFont *font = [UIFont systemFontOfSize:10.0];
    CGSize titleSize = [self.label1.text sizeWithFont:font constrainedToSize:CGSizeMake(MAXFLOAT, 20)];
   // self.nameLabelTextWidth.constant = titleSize.width;
   // [self getSize];
}

- (CGSize)getSize
{

    CGSize sizes = CGSizeMake([UIScreen mainScreen].bounds.size.width, 120);
  //  rect.size = sizes;
 //   self.frame = rect;
    
    [self setNeedsDisplay];
    
    return sizes;//CGSizeMake(CGRectGetMaxX(self.imageViewIcon.frame) * 1.8, CGRectGetMaxY(self.imageViewIcon.frame) + 80);
}
- (void)layoutSubviews {
    UIFont *font = [UIFont systemFontOfSize:10.0];
    CGSize titleSize = [self.label1.text sizeWithFont:font constrainedToSize:CGSizeMake(MAXFLOAT, 20)];
    
    self.lineView.frame = CGRectMake(0, self.height - 1, [UIScreen mainScreen].bounds.size.width, 1);
    
    
  //  self.nameLabelTextWidth.constant = titleSize.width;
    NSLog(@"%@",NSStringFromCGRect(self.lineView.frame));
}
@end
